<?php
class usuario_test extends CI_Controller {
	public $usuario;
	public function __construct() {
		parent::__construct ();
		$this->load->library ( 'unit_test' );
		$this->load->model ( 'Usuario_model' );
		$this->load->model ( 'Rol_model' );
		
		$this->load->database();
		$this->load->dbforge();
		
		// $fields = array(
		// 'session_id' => array(
		// 'type' => 'VARCHAR',
		// 'constraint' => '40',
		// 'null' => FALSE,
		
		// ),
		// 'ip_address' => array(
		// 'type' => 'VARCHAR',
		// 'constraint' => '45',
		// 'null' => FALSE,
		
		// ),
		// 'user_agent' => array(
		// 'type' =>'VARCHAR',
		// 'constraint' => '100',
		// 'null' => FALSE,
		
		// ),
		// 'last_activity' => array(
		// 'type' => 'INT',
		// 'null' => FALSE,
		// ),
		// 'user_data' => array(
		// 'type' => 'TEXT',
		// 'null' => FALSE,
		// ),
		// );
		// $this->dbforge->add_field($fields);
		// $this->dbforge->add_key('session_id', TRUE);
		// $this->dbforge->add_key('last_activity');
		// $this->dbforge->create_table('ci_sessions');
		
		$fields = array (
				'id' => array (
						'type' => 'INTEGER',
						'null' => FALSE,
						'auto-increment' => TRUE
				),
				'nombre' => array (
						'type' => 'TEXT',
						'null' => FALSE 
				),
				'apellido' => array (
						'type' => 'TEXT',
						'null' => FALSE 
				),
				'rendimiento' => array (
						'type' => 'INTEGER',
						'null' => TRUE 
				),
				'equipo' => array (
						'type' => 'INTEGER',
						'null' => TRUE 
				),
				'pass' => array (
						'type' => 'TEXT',
						'null' => FALSE 
				),
				'email' => array (
						'type' => 'TEXT',
						'null' => FALSE 
				),
				'username' => array (
						'type' => 'TEXT',
						'null' => FALSE 
				),
				'rol' => array (
						'type' => 'INTEGER',
						'null' => FALSE 
				) 
		);
		$this->dbforge->add_field ( $fields );
		$this->dbforge->add_key ( 'id', TRUE );
		$this->dbforge->create_table ( 'usuario' );
		
		$fields = array (
				'id' => array (
						'type' => 'INTEGER',
						'null' => FALSE,
						'auto-increment' => TRUE
				),
				'nombre' => array (
						'type' => 'TEXT',
						'null' => FALSE
				)
		);
		$this->dbforge->add_field ( $fields );
		$this->dbforge->add_key ( 'id', TRUE );
		$this->dbforge->create_table ( 'rol' );
		
		$this->usuario = array (
				
				'nombre' => 'maxi',
				'apellido' => 'risota',
				'pass' => 'asd',
				'email' => 'asd',
				'username' => 'qqqqqq',
				'rol' => 1 
		);
	$rol = array(
			'nombre' => 'admin'
	);
		echo $this->Rol_model->guardar($rol);
		
		
	}
	function test_guardar_usuario_permite_recuperarlo() {
		$id = $this->Usuario_model->guardar ( $this->usuario );
		
		
		$usuarioRecuperado = $this->Usuario_model->get_usuario_by_id ( $id );
		
		$this->usuario = $this->Usuario_model->array_to_user ( $this->usuario, $id );
		
		echo $this->unit->run ( $this->usuario, $usuarioRecuperado, 'Test Guardar Usuario' );
	
	}
	function run() {
		$this->test_guardar_usuario_permite_recuperarlo ();
		
	}
}

?>